package com.googlecode.FWT.core
{
	import com.googlecode.FWT.controller.EssayTitleChangedCommand;
	import com.googlecode.FWT.controller.GoBackCommand;
	import com.googlecode.FWT.controller.GoForwardCommand;
	import com.googlecode.FWT.controller.NameChangedCommand;
	import com.googlecode.FWT.controller.NumPagesCommand;
	import com.googlecode.FWT.controller.PrintCommand;
	import com.googlecode.FWT.controller.StartCommand;
	
	import org.puremvc.as3.interfaces.IFacade;
	import org.puremvc.as3.patterns.facade.Facade;

	public class FWTFacade extends Facade
	{
		/**
		 * Return singleton instance. 
		 * @return 
		 */
		public static function getInstance():IFacade
		{
			if(instance == null)
			{
				instance = new FWTFacade();
			}
			
			return instance;
		}
		
		/**
		 * Application startup function.
		 * @param appRef Reference to the main application instance.
		 */
		public static function start(appRef:FWT):void
		{
			getInstance().sendNotification(NotificationNames.APP_START, appRef);
		}
		override protected function initializeController():void
		{
			super.initializeController();
			
			// startup command
			registerCommand(NotificationNames.APP_START, StartCommand);
			// number of pages command
			registerCommand(NotificationNames.NUMBER_PAGES, NumPagesCommand);
			// go back command
			registerCommand(NotificationNames.GO_BACK, GoBackCommand);
			// go forward command
			registerCommand(NotificationNames.GO_FORWARD, GoForwardCommand);
			// name changed command
			registerCommand(NotificationNames.NAME_FIELD, NameChangedCommand);
			// essay title changed command
			registerCommand(NotificationNames.TITLE_FIELD, EssayTitleChangedCommand);
			// print ready command
			registerCommand(NotificationNames.PRINT_READY, PrintCommand);
		}
	}
}